﻿package net.wangit.adm.role;

import net.wangit.Row;
import net.wangit.dev.component.EnumerationTree;
import net.wangit.jdbc.DB;
import net.wangit.view.tree.Tree;

public class PrivilegeEnumerationTree extends EnumerationTree {

	private static final String APPEND_LIMIT = " where dpid is not null and dpid !='' ";
	private boolean disabled;
	private PrivilegeTreeUtil util;

	protected PrivilegeEnumerationTree(boolean disabled, PrivilegeTreeUtil util) {
		this.disabled = disabled;
		this.util = util;
		check = true;
	}

	protected boolean markDataPrivilege(Row row) {
		return false;
	}

	protected String getAppendLimit() {
		return " where dpid is not null and dpid !='' ";
	}

	protected void setGroup(Tree group, String groupId, String name) {
		group.setName((new StringBuilder(String.valueOf(util.getName(name,
				groupId)))).append(" ").append(group.countLeaf()).toString());
		group.setCss("catalog");
		if (disabled)
			group.setCheckAttribute("style='display:none'");
	}

	protected void add2Parent(Tree parent, Tree object) {
		if (object.countLeaf() > 0)
			parent.add(object);
	}

	protected void setEnumeration(Tree object, DB db, String id, String name,
			Row row) throws Exception {
		object.setName(util.getName(name, id));
		util.addDataPrivileges(db, object, "4", id);
		object.setCheckValue("-");
		object.setTitle(row.get("ar"));
		object.setCheckAttribute("style='display:none'");
	}
}
